package b2.widget
{
	import b2.net.*;
	import b2.util.*;
	
	import flash.display.*;
	import flash.text.*;
	import flash.filters.*;

	import org.flixel.*;
	
	public class FocusLostScreen extends Sprite
	{
		private static var instance:FocusLostScreen;
		
		public function FocusLostScreen()
		{
			super();
			//黑色背景
			var bgr:Sprite = new Sprite();
			var gfx:Graphics = bgr.graphics;
			
			gfx.moveTo(0, 0);
			gfx.beginFill(0x000000, 0.5);
			gfx.lineTo(BFont.stageWidth, 0);
			gfx.lineTo(BFont.stageWidth, BFont.stageHeight);
			gfx.lineTo(0, BFont.stageHeight);
			gfx.lineTo(0, 0);
			gfx.endFill();
			
			addChild(bgr);
			
			//鼠标提示画面
			var FocusLostImg:Class = ResourceHelper.getInstance().getClassByName("FocusLostImg");
			var focusLostImg:Sprite = new FocusLostImg();
			focusLostImg.x = (BFont.stageWidth - focusLostImg.width) / 2;
			focusLostImg.y = (BFont.stageHeight - focusLostImg.height) / 2;
			addChild(focusLostImg);
			
			//文字
			var aliasTitleText:TextField = new TextField();
			aliasTitleText.selectable = false;
        	aliasTitleText.autoSize = TextFieldAutoSize.LEFT;
			aliasTitleText.defaultTextFormat = new TextFormat("微软雅黑", 15, 0x000000, true);
			aliasTitleText.filters = [new GlowFilter(0xFFFFFF, 1, 1.3, 1.3, 100, BitmapFilterQuality.HIGH)];
			aliasTitleText.text = "点击鼠标左键\n继续游戏操作";
			aliasTitleText.x = (focusLostImg.width - aliasTitleText.width) / 2;
			aliasTitleText.y = 90;
			focusLostImg.addChild(aliasTitleText);
			
			this.visible = false;
		}
		
		public static function getInstance():FocusLostScreen
		{
			if (!instance)
				instance = new FocusLostScreen();
			return instance;
		}
		
		public function set enable(flag:Boolean):void
		{
			if (flag)
			{
				this.visible = true;
				if (FlxG.keys != null)
				{
					FlxG.keys.W = false;
					FlxG.keys.A = false;
					FlxG.keys.S = false;
					FlxG.keys.D = false;
				}
			}
			else
			{
				this.visible = false;
			}
		}
	}
}